package vn.fpt.fsoft.dao.impl;

import java.util.List;

import org.springframework.orm.hibernate3.support.HibernateDaoSupport;

import vn.fpt.fsoft.dao.ManageUsersDAO;
import vn.fpt.fsoft.entity.AdminAccountInfo;
import vn.fpt.fsoft.entity.UserAccountInfo;

/**
 * Modify TrungPT2 06-Apr-2011
 * */

public class ManageUsersDAOImpl extends HibernateDaoSupport implements
		ManageUsersDAO {
	private String sql = "from AdminAccountInfo";
	@Override
	public void insertAdminUser(AdminAccountInfo adminAccountInfo) {
		getHibernateTemplate().save(adminAccountInfo);
	}

	@Override
	public void deleteAdmin(AdminAccountInfo adminAccountInfo) {
		getHibernateTemplate().delete(adminAccountInfo);
		
	}

	@Override
	public void updateChangedAdminUser(AdminAccountInfo adminAccountInfo) {
		getHibernateTemplate().update(adminAccountInfo);
	}

	@SuppressWarnings("unchecked")
	@Override
	public List<AdminAccountInfo> getAdminList() {
		return getHibernateTemplate().find("from AdminAccountInfo where role=1");
	}

	@SuppressWarnings("unchecked")
	@Override
	public List<AdminAccountInfo> getContributerList() {
		return getHibernateTemplate().find("from AdminAccountInfo where role=0");
	}

	@SuppressWarnings("unchecked")
	@Override
	public List<UserAccountInfo> getMemberList() {
		return getHibernateTemplate().find("from UserAccountInfo");		
	}

	@SuppressWarnings("unchecked")
	@Override
	public List<AdminAccountInfo> getAdminById(String adminId) {
	
		return getHibernateTemplate().find("from AdminAccountInfo where adminID='" + adminId +"'");
	}

	@SuppressWarnings("unchecked")
	@Override
	public List<UserAccountInfo> getUserById(String userId) {
		return getHibernateTemplate().find("from UserAccountInfo where userID='" + userId +"'");
	}

	@Override
	public void deleteUser(UserAccountInfo userAccountInfo) {
		getHibernateTemplate().delete(userAccountInfo);
	}
	
}
